﻿using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Domain.Ticket;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.WorkOrderManagement.CommandHandlers
{
    public class DelteWorkOrderCommandHandler : IRequestHandler<DelteWorkOrderCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<WorkOrder> _workorderRepository;
        public DelteWorkOrderCommandHandler(IBaseRepository<WorkOrder> workorderRepository)
        {
            _workorderRepository = workorderRepository;
        }
        public async Task<APIRequst<int>> Handle(DelteWorkOrderCommand request, CancellationToken cancellationToken)
        {
            var ment=_workorderRepository.GetAll().Where(x=>x.WorkId == request.workid).FirstOrDefault();
            ment.isDel = true;
            ment.DeleteName = request.DeleteName;
            ment.DeleteTime = DateTime.Now;
           await _workorderRepository.Update(ment);

            return await Task.FromResult(new APIRequst<int>
            {
                Code=RequstCode.成功,
                Msg=RequstCode.成功.ToString()
            });
        }
    }
}
